<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <h1>一个promise指定多个成功/失败回调函数（如多个then）, 都会调用吗? </h1>
    <script>
        //答： 当promise改变为对应状态时都会调用。
        const p = new Promise((resolve, reject) => {
            resolve(111);
            //reject();
        });

        // p.then(
        //     value => { console.log("ok1");}, 
        //     reason => {console.log("error1");});
        // 多会调用
        // p.then(
        //     value => { console.log("ok2");}, 
        //     reason => {console.log("error2");});

        // 多层链式then的调用
        p.then(value => {
            console.log(value);
            return 222;
        }, reason => {
            console.log(reason);
        })
        .then(value => {
            console.log("ok",value);
            throw "错误";
        }, reason => {
            console.log("error",reason);
        })
        .then(value => {
            console.log("ok2",value);
        }, reason => {
            console.log("error2",reason);
        })

    </script>
</body>
</html>